package com.mages.classification.service;
import org.springframework.stereotype.Component;

import java.sql.*;

@Component
public class TestService {
    public void test(){
        String currentDirectory = System.getProperty("user.dir");  // 获取当前工作目录
        String databaseFile = "concurrency1.db";  // 数据库文件名，根据实际情况修改
        String jdbcUrl = "jdbc:sqlite:" + currentDirectory + "/" + databaseFile;  // 构建数据库文件路径
        Connection connection = null;

        try {
            // 建立连接
            connection = DriverManager.getConnection(jdbcUrl);

            // 创建表格
            String createTableSql = "CREATE TABLE concurrency (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    "concurrent_count INTEGER, created_at DATETIME DEFAULT CURRENT_TIMESTAMP)";
            Statement statement = connection.createStatement();
            statement.execute(createTableSql);

//             关闭 PreparedStatement
            statement.close();

        } catch (SQLException e) {
            // 处理数据库连接和操作异常
            e.printStackTrace();
        } finally {
            // 关闭连接
            if (connection != null) {
                try {
                    connection.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }

        //
    }
}
